/*
 * 
 * Copyright 2011 visual-analysis-of-cancer.
 * This file is part of visual-analysis-of-cancer.
 * 
 * visual-analysis-of-cancer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * visual-analysis-of-cancer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with kOSMik.  If not, see <http://www.gnu.org/licenses/>.
 *  
 * visual-analysis-of-cancer:
 * An tool to analye the WHO and GLOBOCAN cancer data.
 * http://code.google.com/p/visual-analysis-of-cancer/
 * 
 * 
 * 
 * Authors: Erik Sniegula, Johannes Dahlke
 * 
 * Module:  Programming in Processing for Visual Analytics
 * Group:   20
 * 
 * Created: Aug. 2011
 * Version: 1.0
 *
 */
 




package de.fuberlin.processing.who.cancer.utils;

import de.fuberlin.processing.who.cancer.utils.graphics.BezierRing;
import de.fuberlin.processing.who.cancer.utils.graphics.CurveRing;
import de.fuberlin.processing.who.cancer.utils.graphics.RingSegmentStyle;
import processing.core.PApplet;


public class Graphics {

	public static int getColorWithAlphaChannel( int color, int alpha) {
		return ( color & 0x00FFFFFF) | ( alpha << 0x18);
	}


	private static int constrain( int value, int min, int max) {
		if ( value < min)
			value = min;
		else if ( value > max)
			value = max;
		return value;
	}


	public static int getColorNuance( int color, int nuance) {
		int alpha = ( color & 0xFF000000);
		int oldRed = ( color & 0x00FF0000) >> 0x10;
		int oldGreen = ( color & 0x0000FF00) >> 0x08;
		int oldBlue = color & 0x000000FF;
		int newRed = constrain( oldRed + nuance, 0, 0xFF) << 0x10;
		int newGreen = constrain( oldGreen + nuance, 0, 0xFF) << 0x08;
		int newBlue = constrain( oldBlue + nuance, 0, 0xFF);
		return alpha + newRed + newGreen + newBlue;
	}


	public static void ring( PApplet p, int cx, int cy, float outerCircleWidth,
			float innerCircleWidth) {
    CurveRing.arc( p, cx, cy, outerCircleWidth, innerCircleWidth, 32);
	}

	public static void ring( PApplet p, float cx, float cy, float outerRadius,
			float innerRadius, int countOfSegments, int startSegment, int endSegment) {
    BezierRing.arc( p, cx, cy, outerRadius, innerRadius, countOfSegments, startSegment, endSegment);
	}
	
	public static void ring( PApplet p, float cx, float cy, float outerRadius,
			float innerRadius, int countOfSegments, int ... fractionSegments) {
    BezierRing.arc( p, cx, cy, outerRadius, innerRadius, countOfSegments, fractionSegments);
	}
	
	public static void ring( PApplet p, float cx, float cy, float outerRadius,
			float innerRadius, int countOfSegments, RingSegmentStyle ... fractionSegments) {
    BezierRing.arc( p, cx, cy, outerRadius, innerRadius, countOfSegments, fractionSegments);
	}
	
}
